package com.itheima.mStringTest;

import java.util.Scanner;

/*
       记录小字符串出现次数
 */
public class WorkStringTest02 {
    public static void main(String[] args) {
        //1.键盘录入一个大字符串,再录入一个小字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入大字符串:");
        String big = sc.nextLine();
        System.out.println("请输入小字符串:");
        String small = sc.nextLine();
        int count = 0;
        //2.统计小字符串在大字符串中出现的次数
        int a = big.length();
        int b = small.length();
        for (int i = 0; i < a - b; i++) {
            String c = big.substring(i, i + b);
            if (c.equals(small)) {
                count++;
            }
        }
        if (count > 0) {
            System.out.println("出现了" + count + "次");
        } else {
            System.out.println("没有出现");
        }
    }
}
